package com.jige.jigetodo.model.vo;

import cn.hutool.core.bean.BeanUtil;
import com.jige.jigetodo.common.ErrorCode;
import com.jige.jigetodo.exception.ThrowUtils;
import com.jige.jigetodo.model.entity.User;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

@Data
public class UserVO implements Serializable {

    private static final long serialVersionUID = 1759441697113339380L;
    /**
     * id
     */
    private Long id;
    /**
     * 昵称
     */
    private String userName;
    /**
     * 头像
     */
    private String userAvatar;
    /**
     * 简介
     */
    private String userProfile;

    /**
     * 用户角色
     */
    private String userRole;
    /**
     * 创建时间
     */
    private Date createTime;

    public User voToObj(UserVO userVO) {
        ThrowUtils.throwIf(userVO == null, ErrorCode.PARAMS_ERROR);
        User user = new User();
        BeanUtil.copyProperties(userVO, user);
        return user;
    }

    public UserVO objToVO(User user) {
        ThrowUtils.throwIf(user == null, ErrorCode.PARAMS_ERROR);
        UserVO userVO = new UserVO();
        BeanUtil.copyProperties(user, userVO);
        return userVO;
    }
}
